﻿using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using DiagramDesigner.Controls;
using System.Collections;
using System.Collections.ObjectModel;

namespace DiagramDesigner
{
    public class SimpleTypeContent : ContentControl
    {
        #region ID
        private Guid id;
        public Guid ID
        {
            get { return id; }
        }
        #endregion

        #region DataTypeProperty

        public static readonly DependencyProperty DataTypeProperty =
            DependencyProperty.RegisterAttached("DataType", typeof(String), typeof(SimpleTypeContent));

        public String DataType
        {
            get { return (String)base.GetValue(DataTypeProperty); }
            set { base.SetValue(DataTypeProperty, value); }
        }

        public static String GetDataType(UIElement element)
        {
            return (String)element.GetValue(DataTypeProperty);
        }

        public static void SetDataType(UIElement element, String value)
        {
            element.SetValue(DataTypeProperty, value);
        }

        #endregion

        #region DerivedByProperty

        public static readonly DependencyProperty DerivedByProperty =
            DependencyProperty.RegisterAttached("DerivedBy", typeof(String), typeof(SimpleTypeContent));

        public String DerivedBy
        {
            get { return (String)base.GetValue(DerivedByProperty); }
            set { base.SetValue(DerivedByProperty, value); }
        }

        public static String GetDerivedBy(UIElement element)
        {
            return (String)element.GetValue(DerivedByProperty);
        }

        public static void SetDerivedBy(UIElement element, String value)
        {
            element.SetValue(DerivedByProperty, value);
        }

        #endregion

        #region FinalProperty

        public static readonly DependencyProperty FinalProperty =
            DependencyProperty.RegisterAttached("Final", typeof(String), typeof(SimpleTypeContent));

        public String Final
        {
            get { return (String)base.GetValue(FinalProperty); }
            set { base.SetValue(FinalProperty, value); }
        }

        public static String GetFinal(UIElement element)
        {
            return (String)element.GetValue(FinalProperty);
        }

        public static void SetFinal(UIElement element, String value)
        {
            element.SetValue(FinalProperty, value);
        }

        #endregion

        #region IdProperty

        public static readonly DependencyProperty IdProperty =
            DependencyProperty.RegisterAttached("Id", typeof(String), typeof(SimpleTypeContent));

        public String Id
        {
            get { return (String)base.GetValue(IdProperty); }
            set { base.SetValue(IdProperty, value); }
        }

        public static String GetId(UIElement element)
        {
            return (String)element.GetValue(IdProperty);
        }

        public static void SetId(UIElement element, String value)
        {
            element.SetValue(IdProperty, value);
        }

        #endregion

        #region IsMixedProperty

        public static readonly DependencyProperty IsMixedProperty =
            DependencyProperty.RegisterAttached("IsMixed", typeof(String), typeof(SimpleTypeContent));

        public String IsMixed
        {
            get { return (String)base.GetValue(IsMixedProperty); }
            set { base.SetValue(IsMixedProperty, value); }
        }

        public static String GetIsMixed(UIElement element)
        {
            return (String)element.GetValue(IsMixedProperty);
        }

        public static void SetIsMixed(UIElement element, String value)
        {
            element.SetValue(IsMixedProperty, value);
        }

        #endregion

        #region LineNumberProperty

        public static readonly DependencyProperty LineNumberProperty =
            DependencyProperty.RegisterAttached("LineNumber", typeof(String), typeof(SimpleTypeContent));

        public String LineNumber
        {
            get { return (String)base.GetValue(LineNumberProperty); }
            set { base.SetValue(LineNumberProperty, value); }
        }

        public static String GetLineNumber(UIElement element)
        {
            return (String)element.GetValue(LineNumberProperty);
        }

        public static void SetLineNumber(UIElement element, String value)
        {
            element.SetValue(LineNumberProperty, value);
        }

        #endregion

        #region LinePositionProperty

        public static readonly DependencyProperty LinePositionProperty =
            DependencyProperty.RegisterAttached("LinePosition", typeof(String), typeof(SimpleTypeContent));

        public String LinePosition
        {
            get { return (String)base.GetValue(LinePositionProperty); }
            set { base.SetValue(LinePositionProperty, value); }
        }

        public static String GetLinePosition(UIElement element)
        {
            return (String)element.GetValue(LinePositionProperty);
        }

        public static void SetLinePosition(UIElement element, String value)
        {
            element.SetValue(LinePositionProperty, value);
        }

        #endregion

        #region Name

        public static readonly DependencyProperty NameProperty =
            DependencyProperty.RegisterAttached("Name", typeof(String), typeof(SimpleTypeContent));

        public String Name
        {
            get { return (String)base.GetValue(NameProperty); }
            set { base.SetValue(NameProperty, value); }
        }

        public static String GetName(UIElement element)
        {
            return (String)element.GetValue(NameProperty);
        }

        public static void SetName(UIElement element, String value)
        {
            element.SetValue(NameProperty, value);
        }

        #endregion

        #region NamespacesProperty

        public static readonly DependencyProperty NamespacesProperty =
            DependencyProperty.RegisterAttached("Namespaces", typeof(ObservableCollection<Items>), typeof(SimpleTypeContent));

        public ObservableCollection<Items> Namespaces
        {
            get { return (ObservableCollection<Items>)base.GetValue(NamespacesProperty); }
            set { base.SetValue(NamespacesProperty, value); }
        }

        public static ObservableCollection<Items> GetNamespaces(UIElement element)
        {
            return (ObservableCollection<Items>)element.GetValue(NamespacesProperty);
        }

        public static void SetNamespaces(UIElement element, ObservableCollection<Items> value)
        {
            element.SetValue(NamespacesProperty, value);
        }

        #endregion

        #region ParentProperty

        public static readonly DependencyProperty ParentProperty =
            DependencyProperty.RegisterAttached("Parent", typeof(String), typeof(SimpleTypeContent));

        public String Parent
        {
            get { return (String)base.GetValue(ParentProperty); }
            set { base.SetValue(ParentProperty, value); }
        }

        public static String GetParent(UIElement element)
        {
            return (String)element.GetValue(ParentProperty);
        }

        public static void SetParent(UIElement element, String value)
        {
            element.SetValue(ParentProperty, value);
        }

        #endregion

        #region QualifiedNameProperty

        public static readonly DependencyProperty QualifiedNameProperty =
            DependencyProperty.RegisterAttached("QualifiedName", typeof(String), typeof(SimpleTypeContent));

        public String QualifiedName
        {
            get { return (String)base.GetValue(QualifiedNameProperty); }
            set { base.SetValue(QualifiedNameProperty, value); }
        }

        public static String GetQualifiedName(UIElement element)
        {
            return (String)element.GetValue(QualifiedNameProperty);
        }

        public static void SetQualifiedName(UIElement element, String value)
        {
            element.SetValue(QualifiedNameProperty, value);
        }

        #endregion

        #region SourceUriProperty

        public static readonly DependencyProperty SourceUriProperty =
            DependencyProperty.RegisterAttached("SourceUri", typeof(String), typeof(SimpleTypeContent));

        public String SourceUri
        {
            get { return (String)base.GetValue(SourceUriProperty); }
            set { base.SetValue(SourceUriProperty, value); }
        }

        public static String GetSourceUri(UIElement element)
        {
            return (String)element.GetValue(SourceUriProperty);
        }

        public static void SetSourceUri(UIElement element, String value)
        {
            element.SetValue(SourceUriProperty, value);
        }

        #endregion

        #region TypeCodeProperty

        public static readonly DependencyProperty TypeCodeProperty =
            DependencyProperty.RegisterAttached("TypeCode", typeof(String), typeof(SimpleTypeContent));

        public String TypeCode
        {
            get { return (String)base.GetValue(TypeCodeProperty); }
            set { base.SetValue(TypeCodeProperty, value); }
        }

        public static String GetTypeCode(UIElement element)
        {
            return (String)element.GetValue(TypeCodeProperty);
        }

        public static void SetTypeCode(UIElement element, String value)
        {
            element.SetValue(TypeCodeProperty, value);
        }

        #endregion

        #region UnhandledAttributesProperty

        public static readonly DependencyProperty UnhandledAttributesProperty =
            DependencyProperty.RegisterAttached("UnhandledAttributes", typeof(ObservableCollection<Items>), typeof(SimpleTypeContent));

        public ObservableCollection<Items> UnhandledAttributes
        {
            get { return (ObservableCollection<Items>)base.GetValue(UnhandledAttributesProperty); }
            set { base.SetValue(UnhandledAttributesProperty, value); }
        }

        public static ObservableCollection<Items> GetUnhandledAttributes(UIElement element)
        {
            return (ObservableCollection<Items>)element.GetValue(UnhandledAttributesProperty);
        }

        public static void SetUnhandledAttributes(UIElement element, ObservableCollection<Items> value)
        {
            element.SetValue(UnhandledAttributesProperty, value);
        }

        #endregion

        static SimpleTypeContent()
        {
            // set the key to reference the style for this control
            FrameworkElement.DefaultStyleKeyProperty.OverrideMetadata(
                typeof(SimpleTypeContent), new FrameworkPropertyMetadata(typeof(SimpleTypeContent)));
        }

        public SimpleTypeContent(Guid id)
        {
            this.id = id;
        }

        public SimpleTypeContent()
            : this(Guid.NewGuid())
        {
            this.Style = FindResource("DesignerItemContentXsdSimpleTypeDefaultStyle") as Style;
            this.ApplyTemplate();
            this.SetEventHandlers();
        }

        public SimpleTypeContent(string contentTemplateName)
            : this(Guid.NewGuid())
        {
            this.Style = FindResource(contentTemplateName) as Style;
            this.ApplyTemplate();
            this.SetEventHandlers();
        }

        private void SetEventHandlers()
        {

        }

        public void DisableContentControl(String name)
        {
            this.ApplyTemplate();
            Control control = this.Template.FindName(name, this) as Control;
            control.Visibility = Visibility.Collapsed;
        }

        public void EnableContentControl(String name)
        {
            this.ApplyTemplate();
            Control control = this.Template.FindName(name, this) as Control;
            control.Visibility = Visibility.Visible;
        }
    }
}